#!/usr/bin/python

from system.core.model import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import (
    Integer,
    CHAR,
    TEXT,
    Enum,
    DATETIME,
    )

"""
Class       : SchedulerRecords
Description : SchedulerRecords
"""

class SchedulerRecord(Base):
    """
    __tablename__: specified table name
    """
    __tablename__ = "Scheduler"

    """
    id          : scheduler record id
    """
    id          = Column(Integer, primary_key = True)

    """
    task_name   : scheduler task name
    """
    task_name   = Column(CHAR(255), nullable=False)

    """
    module_name : executor module name
    """
    module_name = Column(CHAR(64), nullable = False)

    """
    class_name : executor class name
    """
    class_name = Column(CHAR(64), nullable = False)

    """
    arguments  : a json text which declare scheduler job arguments
    """
    arguments  = Column(TEXT, nullable = True)

    """
    type       : a scheduler job type
    """
    type       = Column(Enum('CTONTAB', 'INTERVAL', 'DATETIME'), nullable = False)

    """
    time_val   : a json text which store scheduler time 
    """
    time_val   = Column(TEXT, nullable = False)

    """
    start_datetime : scheduler start datetime
    """
    start_datetime = Column(DATETIME, nullable = False)

    """
    end_datetime   : scheduler end datetime
    """
    end_datetime   = Column(DATETIME, nullable = False)

    """
    is_active  : enum show if is scheduler active
    """
    is_active  = Column(Enum('true', 'false'), nullable = False)


    """
    __repr__
    """
    def __repr__(self):
        return "<SchedulerRecord(\
                id='%s',\
                task_name='%s',\
                module_name='%s',\
                class_name='%s',\
                arguments='%s',\
                type='%s',\
                time_val='%s',\
                start_datetime='%s',\
                end_datetime='%s',\
                is_active='%s'\
                )>" % (
                self.id,
                self.task_name,
                self.module_name,
                self.class_name,
                self.arguments,
                self.type,
                self.time_val,
                self.start_datetime,
                self.end_datetime,
                self.is_active
                )

